package com.qianclass.talklive.app.json.ImSendMessge;

import com.google.gson.Gson;
import com.qianclass.talklive.app.bean.AuthOpenFile;
import com.qianclass.talklive.app.bean.WebTurnCommandBean;
import com.qianclass.talklive.app.bean.WhiteBoardBean;
import com.qianclass.talklive.app.im.IMEgine;
import com.qianclass.talklive.app.utils.Constant;
import com.qianclass.talklive.app.utils.LogUtil;
import com.qianclass.talklive.app.utils.ThreadUtils;

/**
 * Created by Admin on 2017/3/13.
 */

public class SendPageturnMessge {

    //发送跳转翻页命令
    public static void sendMessge(int FileID, final IMEgine egine, final String group){
        AuthOpenFile authOpenFile = new AuthOpenFile();

        AuthOpenFile.MessageBean messageBean = new AuthOpenFile.MessageBean();
        messageBean.setType("whiteboard");

        WhiteBoardBean whiteboardBean = new WhiteBoardBean();
        whiteboardBean.setSubcommand("pageturn");
        whiteboardBean.setFileid(FileID);
        whiteboardBean.setCurrentpage(1);
        whiteboardBean.setPagenum(1);

        messageBean.setWhiteboard(whiteboardBean);
        authOpenFile.setMessage(messageBean);

        Gson gson = new Gson();
        final String jsonString = gson.toJson(authOpenFile);
        ThreadUtils.runOnSubThread(new Runnable() {
            @Override
            public void run() {
                egine.SendGroupMessage(Constant.WHITEBOARDMSGTYPE, group, jsonString);
            }
        });
        LogUtil.i("发送跳转翻页命令" ,jsonString);
    }

    public static void sendMessge(String fileDir, int fileId, int currentPage, int pageNum, final IMEgine egine, final String group){
        AuthOpenFile authOpenFile = new AuthOpenFile();

        AuthOpenFile.MessageBean messageBean = new AuthOpenFile.MessageBean();
        messageBean.setType("whiteboard");

        WhiteBoardBean whiteboardBean = new WhiteBoardBean();
        whiteboardBean.setSubcommand("pageturn");
        whiteboardBean.setFiledir(fileDir);
        whiteboardBean.setFileid(fileId);
        whiteboardBean.setCurrentpage(currentPage);
        whiteboardBean.setPagenum(pageNum);

        messageBean.setWhiteboard(whiteboardBean);
        authOpenFile.setMessage(messageBean);

        Gson gson = new Gson();
        final String jsonString = gson.toJson(authOpenFile);
        ThreadUtils.runOnSubThread(new Runnable() {
            @Override
            public void run() {
                egine.SendGroupMessage(Constant.WHITEBOARDMSGTYPE, group, jsonString);
            }
        });
        LogUtil.i("发送跳转翻页命令" ,jsonString);
    }

    //发送Web动作跳转命令
    public static void sendWebTurn(int fileId, int currentPage, int currentaction, final IMEgine egine, final String group){

        WebTurnCommandBean webTurnCommandBean = new WebTurnCommandBean();
        WebTurnCommandBean.MessageBean messageBean = new WebTurnCommandBean.MessageBean();
        WebTurnCommandBean.MessageBean.WhiteboardBean whiteboardBean = new WebTurnCommandBean.MessageBean.WhiteboardBean();
        whiteboardBean.setFileid(fileId);
        whiteboardBean.setCurrentpage(currentPage);
        whiteboardBean.setCurrentaction(currentaction);
        whiteboardBean.setSubcommand("webturn");

        messageBean.setType("whiteboard");
        messageBean.setWhiteboard(whiteboardBean);
        webTurnCommandBean.setMessage(messageBean);

        Gson gson = new Gson();
        final String jsonString = gson.toJson(webTurnCommandBean);
        ThreadUtils.runOnSubThread(new Runnable() {
            @Override
            public void run() {
                egine.SendGroupMessage(Constant.WHITEBOARDMSGTYPE, group, jsonString);
            }
        });
        LogUtil.i("发送跳转翻页命令" ,jsonString);
    }
}
